package com.springStudy.core.environment;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Profile;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.AbstractEnvironment;
import org.springframework.core.env.StandardEnvironment;

public class EnviromentDemo {
    /**
     * Environment 通过向环境注入系统环境与启动时的参数，在解析占位符时将参数注入
     */
    @Test
    public  void test01() {
        System.setProperty("ylwTest", "测试下");
        StandardEnvironment environment = new StandardEnvironment();
        //PropertyResolver 解析占位符
        System.out.println(environment.resolvePlaceholders("${key:defaultValue}"));
        System.out.println(environment.resolvePlaceholders("${os.name:mac}"));
        System.out.println(environment.resolvePlaceholders("${ylwTest:defaultValue}"));
        System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "dev");
        String[] activeProfiles = environment.getActiveProfiles();
        for (String activeProfile : activeProfiles) {
            System.out.println(activeProfile);
        }

    }
}
